package controller;

import com.google.gson.Gson;
import org.aspectj.weaver.ast.Not;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Notice;
import service.NoticeService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @CrossOrigin
    @RequestMapping("/insert")
    public void insert(HttpServletResponse response,String author,String tittle,String time,String content){
        System.out.println("发布公告");
        noticeService.insert(author,tittle,time,content);
        System.out.println(time+content);
    }

    @CrossOrigin
    @RequestMapping("/select")
    public void select(HttpServletResponse response) throws IOException {
        System.out.println("公告查看调用");
        String JsonStr=new Gson().toJson(noticeService.select());
        System.out.println(JsonStr);
        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JsonStr);
    }
}
